package com.qfjy.homework.huzhongtian.factory;

import com.qfjy.homework.huzhongtian.Circle;
import com.qfjy.homework.huzhongtian.Shape;

import java.util.HashMap;

/**
 * @author: 胡中天
 * @date: 2022/6/29 19:08
 * @VERSION: 1.0
 */
public class ShapeFactory {

    private  static  final  HashMap<String, Shape>circleMap=new HashMap<>();

    public static  Shape getCircle(String color){
//        如果有该颜色的圆，即集合中的key存在，就从集合中取出
         Circle circle =(Circle) circleMap.get(color);
//            如果没有则new一个新的
         if(circle==null){
             circle=new Circle(color);
             circleMap.put(color,circle);
             System.out.println("创建的圆的颜色为："+color);
         }
         return  circle;
    }

}






